package com.atguigu.gmall.web.controller;

import com.atguigu.gmall.item.client.ItemFeignClient;
import com.atguigu.gmall.model.product.SkuInfo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;

import java.util.Map;

/**
 * @Author: lx
 * @Time: 15:41
 * @Description:
 *  商品详情页面渲染
 */
@Controller
public class ItemController {
    //进入商品详情页面  https://item.gmall.com  /100007299121.html

    @Autowired
    private ItemFeignClient itemFeignClient;
    @GetMapping("/{skuId}.html")
    public String getItem(@PathVariable Long skuId, Model model){
        Map map = itemFeignClient.getItem(skuId);
        //检查数据
   /*     SkuInfo skuInfo = (SkuInfo) map.get("skuInfo");
        if(skuInfo.getId() == null){
            //有人攻击 是空结果
            //重定向到首页
        }*/

        model.addAllAttributes(map);
        return "item/index";
    }
}
